<?php
// +----------------------------------------------------------------------
// | sfadmin - Suifeng Administration
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2020 http://suifeng.tech All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: suifeng <1787585212@qq.com>
// +----------------------------------------------------------------------

namespace suifeng\builder\form\validator;

use suifeng\builder\form\Validator;

class Required extends Validator
{
    /**
     * 错误信息。
     *
     * @var string
     */
    public $message = '{control.label} 必须输入。';

    /**
     * 验证方法。
     */
    protected function _validate_core()
    {
        $value = $this->_get_control_value();

        if ($value === null || (is_string($value) && strlen($value) == 0)) {
            $this->errors[] = $this->_format_message(null);
        }
    }
}
